# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=nbconvert
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python3-jupyter-${_realname}")
pkgver=5.3.1
pkgrel=1
pkgdesc="Convert Jupyter notebooks to other formats (mingw-w64)"
arch=('any')
url='https://pypi.python.org/pypi/nbconvert'
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python3"
         "${MINGW_PACKAGE_PREFIX}-python3-jupyter_client"
         "${MINGW_PACKAGE_PREFIX}-python3-jupyter-nbformat"
         "${MINGW_PACKAGE_PREFIX}-python3-pygments"
         "${MINGW_PACKAGE_PREFIX}-python3-mistune"
         "${MINGW_PACKAGE_PREFIX}-python3-jinja"
         "${MINGW_PACKAGE_PREFIX}-python3-entrypoints"
         "${MINGW_PACKAGE_PREFIX}-python3-traitlets"
         "${MINGW_PACKAGE_PREFIX}-python3-pandocfilters"
         "${MINGW_PACKAGE_PREFIX}-python3-bleach"
         "${MINGW_PACKAGE_PREFIX}-python3-testpath"
         )
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/jupyter/${_realname}/archive/$pkgver.tar.gz")
sha256sums=('0ca7dcaa1f554bfe6e57b218dd4c1e1dd8019e5e3561e865abfc1c6a3bdb4000')

prepare() {
  cd "$srcdir"/

  rm -rf python3-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python3-build-${CARCH}"
}

build() {
  msg "Python 3 build for ${CARCH}"
  cd "${srcdir}/python3-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

package() {
  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in ${pkgdir}${MINGW_PREFIX}/bin/*.py; do
    sed -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i ${_f}
  done

  install -Dm644 "LICENSE" "$pkgdir/${MINGW_PREFIX}/share/licenses/$pkgname/LICENSE"
}

